package 富婆梦.第一阶段.Java基础视频学习.IO流学习.字节流练习;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.Java基础视频学习.IO流学习.FileOutputStream练习
 * @ClassName: FileOutputStreamDemo1
 * @Author: hemengjin
 * @Description:
 * @Date:2021/11/21 19:37
 * @Version: 1.0
 */
public class FileOutputStreamDemo1 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\tool\\a.txt");
        FileOutputStream fo = new FileOutputStream(file);
        //写一个字节
        fo.write(98);
        //写一个字节数组
        byte[] bytes = {65,66,67,68};
        fo.write(bytes);
        //写字节数组的一部分，开始索引，写如个数
        fo.write(bytes,2,2);
        //写入字节数组的简便方式，写字符串
        fo.write("hello".getBytes());

        //文件续写和换行
        FileOutputStream fileOutputStream = new FileOutputStream(file,true);
        fileOutputStream.write("\r\nhello".getBytes());
        fileOutputStream.write("\r\nword".getBytes());

        //关流
        fo.close();
    }
}
